package com.chocho.producerserver.dao;

import com.chocho.producerserver.bean.QCollection;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by chocho on 2022/4/10.
 */
@Mapper
@Repository
public interface QCollectionDao {

    @Insert("INSERT INTO op_qcollection (qcollection_id, qcollection_name, user_id, create_time, end_time, qcollection_status) " +
            "VALUES(#{qcollectionId}, #{qcollectionName}, #{userId}, #{createTime}, #{endTime}, #{qcollectionStatus})")
    int insert(QCollection collection);

    @Select("<script>" +
            "SELECT * FROM op_qcollection " +
            "<where>" +
            "<trim suffixOverrides='and'> " +
            "<if test=\"qcollectionId != \'\' and qcollectionId != null\"> qcollection_id like CONCAT('%',#{qcollectionId},'%')</if> " +
            "</trim> " +
            "<trim suffixOverrides='and'> " +
            "<if test=\"qcollectionName != \'\' and qcollectionName != null\"> qcollectionName like CONCAT('%',#{qcollectionName},'%')</if> " +
            "</trim> " +
            "<trim suffixOverrides='and'> " +
            "<if test=\"userId != \'\' and userId != null\"> user_id like CONCAT('%',#{userId},'%')</if> " +
            "</trim> " +
            "<trim suffixOverrides='and'> " +
            "<if test=\"qcollectionStatus != \'\' and qcollectionStatus != null\"> qcollectionStatus like CONCAT('%',#{qcollectionStatus},'%')</if> " +
            "</trim> " +
            "</where>" +
            "</script>")
    List<QCollection> getCollectionByQuery(Map<String, Object> map);

    @Delete("<script>" +
            "DELETE FROM op_qcollection WHERE qcollection_id in " +
            "<foreach collection=\"list\" open=\"(\" close=\")\" separator=\",\"  item=\"item\"> #{item}" +
            "</foreach>" +
            "</script>")
    int delete(List<String> idList);

    @Update("UPDATE op_qcollection " +
            "SET qcollection_name = #{qcollectionName}, end_time = #{endTime}, qcollection_status = #{qcollectionStatus} " +
            "WHERE qcollection_id = #{qcollectionId}")
    int update(QCollection collection);

    @Select("<script>" +
            "SELECT * FROM op_qcollection WHERE qcollection_id in " +
            "<foreach collection=\"list\" open=\"(\" close=\")\" separator=\",\"  item=\"item\"> #{item}" +
            "</foreach>" +
            "</script>")
    List<QCollection> getByIdList(List<String> idList);

    @Select("SELECT COUNT(qcollection_id) FROM op_qcollection")
    int getMaxNum();
}
